package io.hepu.robotize.exception;

import io.hepu.robotize.enums.IStatus;

/*
 * Global System RuntimeException
 */
public class GlobalException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    private final int code;
    private final String message;
    private final Object data;

    public GlobalException(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public GlobalException(int code, String message) {
        this(code, message, null);
    }

    public GlobalException(IStatus status) {
        this(status.code(), status.message(), null);
    }

    public GlobalException(IStatus status, Object data) {
        this(status.code(), status.message(), data);
    }

    public static GlobalException of(int code, String message) {
        return new GlobalException(code, message);
    }

    public static GlobalException of(IStatus status) {
        return new GlobalException(status);
    }

    public static GlobalException of(IStatus status, Object data) {
        return new GlobalException(status, data);
    }

    public int getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }

    @Override
    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return "GlobalException {code=" + getCode() + "; message=" + getMessage() + "; data=" + getData() + "}";
    }
}
